/*
 * Copyright (c) 2011 Jean-Marc Perronne
 * Ensisa, 12 rue des Freres Lumieres, F-68093 Mulhouse cedex
 * All rights reserved.
 *
 * The copyright of this software is owned by Werner Randelshofer. 
 * You may not use, copy or modify this software, except in  
 * accordance with the license agreement you entered into with  
 * Jean-Marc Perronne. For details see accompanying license terms. 
 */

package fr.uha.ensisa.jmp.drone.recorder;

import java.io.IOException;

public  class Recorder<T>
{
	protected boolean recording;
	protected Writer<T> writer;

	public Recorder(Writer<T> writer)
	{
		this.writer = writer;
		this.recording = false;
	}
	
	public Writer<T> getWriter()
	{
		return this.writer;
	}

	public void setWriter(Writer<T> writer)
	{
		this.writer = writer;
	}
	
	public void start() throws IOException
	{
		if (this.recording) this.stop();
		this.recording = true;
	}
	
	public void stop() throws IOException
	{
		this.recording = false;
		this.writer.close();
	}
	
	public void record(T record)  throws IOException
	{
		if(this.recording)
			this.writer.write(record);
	}

	public boolean recording()
	{
		return this.recording;
	}
	
}
